package com.itheima.day10.myStream.test2;


import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.stream.Stream;

public class Demo {
    public static void main(String[] args) {
        // 单列集合
        // method1();

        // 双列集合
        // method2();

        // 数组
        // method3();

        // 同种数据的多个数据
        //method4();

    }

    private static void method4() {
        Stream.of(1, 2, 3, 4, 5).forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer i) {
                System.out.print(i + " ");
            }
        });
    }

    private static void method3() {
        int[] arr = {1, 2, 3, 4, 5};
        Arrays.stream(arr).forEach(new IntConsumer() {
            @Override
            public void accept(int i) {
                System.out.print(i + " ");
            }
        });
    }

    private static void method2() {
        HashMap<String, String> hs = new HashMap<>(Map.ofEntries(
                Map.entry("张三", "湖南"),
                Map.entry("李四", "四川"),
                Map.entry("王五", "新疆")
        ));
        // 先获取所有键的集合，再把集合中的所有键放到Stream流中
        hs.keySet().stream().forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s + "---" + hs.get(s));
            }
        });

        System.out.println();
        hs.keySet().stream().forEach(s -> System.out.println(s + "---" + hs.get(s)));
        System.out.println();
        hs.entrySet().stream().forEach(s -> System.out.println(s.getKey() + "---" + s.getValue()));
    }

    private static void method1() {
        ArrayList<String> al = new ArrayList<>(List.of("aaa", "bbb", "ccc"));

        al.stream().forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.print(s + " ");
            }
        });
        al.stream().forEach(s -> System.out.print(s + " "));
    }
}
